#ifndef _VGA_H
#define _VGA_H

// #define VGA_TIMEOUT 0x000FFFFF
#define VGA_TIMEOUT 0x000007FF

#define HSYN	BIT21			//PWM5 P0.21
#define VSYN	BIT22			//GPIO P0.22

#define RED BIT17
#define GREEN BIT18
#define BLUE BIT19

#define RGB	(RED | GREEN | BLUE)

#define R_MASK 0x2
#define G_MASK 0x4
#define B_MASK 0x8
#define RG_MASK 0x6
#define RB_MASK 0xA
#define GB_MASK 0xC
#define RGB_MASK 0xE

#define HFREQ	0x0810				// Horz synch frequency
#define HSYNW	0xE2		// Horz synch width

#define SET_VGA_VSYN_DIR (FIO0DIR |= VSYN)
#define SET_VGA_RGB_DIR (FIO1DIR |= RGB)

#define CLR_VSYN (FIO0CLR = VSYN)
#define SET_VSYN (FIO0SET = VSYN)

#define CLR_RGB (FIO1CLR = RGB)
#define SET_RGB (FIO1SET = RGB)

#define CLR_RED (FIO1CLR = RED)
#define SET_RED (FIO1SET = RED)

#define CLR_GREEN (FIO1CLR = GREEN)
#define SET_GREEN (FIO1SET = GREEN)
#define CLR_BLUE (FIO1CLR = BLUE)
#define SET_BLUE (FIO1SET = BLUE)

//  Since the outputs are being inverted, set the opposite
//  of what we want.
// #define STATE_1 0x8
#define STATE_1 0x6
// #define STATE_2 0x4
#define STATE_2 0xa
// #define STATE_3 0x2
#define STATE_3 0xc
#define STATE_OFF 0xe
// #define STATE_OFF 0x0

enum VSYNC_STATES_E
{
  P_START = 1,
  Q_START = 3,
  R_START = 34,
  S_START = 514,
  S_END = 528
};

void init_vga(void);

void init_step(void);

#endif // _VGA_H
